import logging
import time
import os


def get_log(name):
    # 第一步：创建一个logger
    logger = logging.getLogger(name)
    logger.setLevel(logging.INFO)

    # 设置日志信息、输出路径、格式
    times = time.strftime('%Y%m%d',time.localtime(time.time()))
    path = os.path.dirname(os.path.abspath('.'))
    all_log_path = os.path.join(path, 'Logs/All_Log/')
    error_log_path = os.path.join(path, 'Logs/Error_Log/')

    all_log_name = all_log_path+times+'.log'
    error_log_name = error_log_path+times+'.log'

    all_handle = logging.FileHandler(all_log_name, encoding='utf-8')
    all_handle.setLevel(logging.INFO)

    error_handle = logging.FileHandler(error_log_name, encoding='utf-8')
    error_handle.setLevel(logging.ERROR)

    stream = logging.StreamHandler()
    stream.setLevel(level=logging.DEBUG)

    all_log_formatter = logging.Formatter('%(asctime)s -%(name)s - %(levelname)s - %(message)s')

    error_log_formatter = logging.Formatter('%(asctime)s -%(name)s - %(levelname)s - %(message)s')

    all_handle.setFormatter(all_log_formatter)
    error_handle.setFormatter(error_log_formatter)

    logger.addHandler(all_handle)
    logger.addHandler(error_handle)
    logger.addHandler(stream)

    return logger

